/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.fjut.se1603.mybatis.dao;

import edu.fjut.se1603.mybatis.entity.SysUser;
import java.util.List;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;

/**
 *
 * @author danny
 */
public interface SysUserDao {
    
    @Select("select * from sys_user where id=#{id}")
    SysUser selectByPrimaryKey(int id);
    
    @Select("select * from sys_user")
    List<SysUser> select();
    
    @Update({
        "update sys_user set USER_NAME=#{userName},",
        "PASSWORD=#{password},",
        "SEX=#{sex},",
        "BIRTHDAY=#{birthday},",
        "IDENTITY_CODE=#{identityCode},",
        "EMAIL=#{email},",
        "MOBILE=#{mobile},",
        "ADDRESS=#{address},",
        "STATUS=#{status}",
        " where ID=#{id}"
    })
    int update(SysUser user);
    
    @Insert({
        "insert into sys_user (ACCOUNT,USER_NAME,PASSWORD,SEX,BIRTHDAY,IDENTITY_CODE,EMAIL,MOBILE,ADDRESS,STATUS) ",
        "values (#{account},#{userName},#{password},#{sex},#{birthday},#{identityCode},#{email},#{mobile},#{address},#{status})"
    })
    @SelectKey(before = false, keyProperty = "id", resultType = Long.class, statement = "select LAST_INSERT_ID()")
    int insert(SysUser user);
    
    @SelectProvider(type = SysUserDaoSqlProvider.class, method = "selectByExample")
    List<SysUser> selectByExample(SysUser user);
}
